<template>
  <div class="analysis-page" style="font-size: initial">
    <section class="container">
      <SideTree :tempList="tempList" />
      <div class="main">
        <div class="search-wrap">
          <!-- 检索 -->
          <div class="search-left-box">
            <Search
              listOrAnalysisType="analysis"
              :ctNavID="ctNavID"
              :showSearchNav="false"
            ></Search>
          </div>
          <div class="tools">
            <button
              v-if="routeType !== '文献库' && routeType !== 'zixun'"
              @click="showExport"
            >
              <i class="iconfont icon-daochubaogao"></i>导出报告
            </button>
            <span @click="toDownloadCenter" class="download-center-btn"
              >进入报告中心</span
            >
          </div>
        </div>
        <!-- 图表模型 -->
        <ModeIndex />
      </div>
      <!-- 图表配置 -->
      <GraphConfig />
    </section>
    <!-- 导出报告 -->
    <ExportReport ref="exportReport" :exportReportType="ctNavID" />
  </div>
</template>

<script>
import { mapState } from "vuex";
import SideTree from "./SideTree";
import Search from "@/views/modules/DataCenter/child/base/Search.vue";
import GraphConfig from "./GraphConfig";
import ExportReport from "./ExportReport";
import base64 from "@/utils/base64.js";
// 图表模型
import ModeIndex from "./mode/index";
// 申请人（发明人）分析
// 申请量趋势分析
// import ApplicationTrend from './applicant/ApplicationTrend'

export default {
  components: {
    SideTree,
    Search,
    GraphConfig,
    ExportReport,
    ModeIndex,
  },
  data() {
    return {
      ctNavID: "",
      routeType: "",
      searchTxt: "",
      tempList: [],
      all_total: 0,
      loading: true,
    };
  },
  watch: {
    $route(n, o) {
      if (n.query.type != o.query.type) {
        this.getTemplate();
      }
      this.ctNavID = n.query.type;
    },
  },

  computed: {
    ...mapState([
      "searchWord",
      "advancedSearchWord",
      "createSq",
      "analysisScreen",
      "analysisChooseScreen",
    ]),
  },

  created() {
    const query = this.$route.query;
    this.ctNavID = query.type || "";
    if (query.keyword) {
      this.$store.commit("setSearchWord", query.keyword);
    }
    if (query.sq) {
      this.$store.commit("setSearchWord", query.sq);
    }
    const token = query.token;
    // 存token
    if (token) {
      this.$cookie.set("token", token);
    }
    // this.$store.commit("setSearchWord", "b/hjhsjfhjs>sifjis/");

    this.getTemplate();
  },
  mounted() {
    // this.$Bus.$on("dcData", (list) => {});
    this.$Bus.$on("beginSearch", (status) => {
      if (status == 1) {
        this.loading = true;
      } else if (status == 2) {
        this.loading = false;
      }
    });
  },
  methods: {
    // 从数据库获取模板
    getTemplate() {
      // console.log(1);
      const type = this.$route.query.type;
      this.$get(this.$Url.analysis.template, {
        dbid: type,
      })
        .then((res) => {
          this.tempList = res.data[type];
        })
        .catch((err) => {});
    },
    // 导出报告
    showExport() {
      let subjects = this.$route.query.subjects;
      let str = "";
      if (this.searchTxt !== "") {
        str += this.searchTxt;
        if (subjects) {
          str += " and " + `subjects/${base64.decode(subjects)}`;
        }
      } else if (subjects) {
        str += `subjects/${base64.decode(subjects)}`;
      }
      let ops = {
        sq: str,
        subjects: (subjects && base64.decode(subjects)) || "",
        all_total: this.all_total,
      };
      this.$refs.exportReport.init(ops);
    },
    toDownloadCenter() {
      this.$nextTick(() => {
        let routerUrl = this.$router.resolve({
          // name: "downloadCenter",
          name: "reportIndex",
          // query: {
          //   type: this.ctNavID,
          // },
        });
        window.open(routerUrl.href, "_blank");
      });
    },
  },
  beforeDestroy() {
    this.$Bus.$off("dcData");
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .el-button--primary {
    border-color: $color141 !important;
    background-color: $color141 !important;
  }
  .el-checkbox__label {
    font-size: 12px !important;
    color: $color32;
  }
  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #000 !important;
  }
  .el-dropdown-menu__item {
    font-size: 12px !important;
  }
  .el-select-dropdown__item.selected {
    color: $color141 !important;
  }
  .el-pager li.active {
    color: $color141 !important;
  }
  // 选择数据源
  .el-dialog__header {
    background-color: $color4;
  }
  .el-dialog__body {
    // padding: 0 20px !important;
  }
  .group-title-cnt .el-checkbox__label {
    font-size: 14px;
    font-weight: 700;
    color: #000 !important;
  }
  .group-world {
    .el-checkbox__input {
      line-height: normal;
    }
    .el-checkbox__label {
      font-size: 12px;
      color: #000 !important;
    }
  }
  // 筛选项
  .tree-items {
    .el-checkbox__label {
      padding-left: 5px;
      font-size: 12px !important;
    }
  }
  .mode-select,
  .sort-select {
    .el-input__inner {
      height: 34px;
      line-height: 34px;
      border: none;
      color: $color30;
    }
  }
  // 分页
  .pagination .page-size .el-input__inner {
    height: 28px;
    line-height: 28px;
  }
  .el-select-dropdown__item {
    text-indent: 10px;
  }

  // 参数配置
  .search-time {
    // .el-date-editor.el-input {
    //   width: 142px;
    //   .el-input__inner {
    //     border: 0;
    //     background-color: $color2;
    //   }
    // }
  }
  // 分析页面
  .m-slot {
    &.no-margin {
      margin-bottom: 0 !important;
    }
    .btn-group {
      .icon {
        font-size: 18px !important;
      }
    }
    h4 {
      line-height: 40px;
      font-size: 13px;
      font-weight: normal;
      color: $color130;
    }
    .date-box {
      position: relative;
      display: inline-block;
      margin-right: 20px;
      font-size: 13px;
      .tit {
        display: inline-block;
        padding-right: 14px;
        font-size: 12px;
        color: $color6;
      }
      .search-time {
        display: inline-flex;
        align-items: center;
        .split {
          position: relative;
          display: inline-block;
          width: 10px;
          margin: 0 10px;
          &:before {
            position: absolute;
            top: 50%;
            left: 0;
            width: 100%;
            height: 1px;
            background-color: $color31;
            content: "";
          }
        }
      }
    }
    .select-box {
      position: relative;
      display: inline-block;
      margin-right: 20px;
      font-size: 13px;
      .tit {
        display: inline-block;
        padding-right: 14px;
        font-size: 12px;
        color: $color6;
      }
      .select {
        width: 142px;
        .el-input__inner {
          padding-left: 15px;
          border: 0;
          font-size: 12px;
          background-color: $color4;
        }
        // .el-input__inner {
        //   border: 0;
        //   background-color: $color2;
        // }
      }
    }
    .right-tools {
      position: absolute;
      top: 0;
      right: 0;
      width: 176px;
      padding-right: 10px;
      text-align: right;
      > span {
        display: inline-block;
        width: 78px;
        line-height: 26px;
        border: 1px solid $mainColor;
        border-radius: 30px;
        margin-left: 10px;
        text-align: center;
        font-size: 12px;
        color: $color2;
        background-color: $mainColor !important;
        cursor: pointer;
        &:nth-of-type(1) {
          margin-left: 0;
        }
      }
    }
  }

  // 分析-图表
  .chart-box {
    position: relative;
    width: 100%;
    .chart {
      width: 100%;
      height: calc(100vh - 0.7rem - 40px - 40px - 70px - 41px - 70px);
    }
    .chart-loading-box {
      position: absolute;
      top: 50%;
      left: 0;
      width: 100%;
      // margin-top: -5em;
      max-height: 100%;
    }
  }
  .picker-box {
    position: relative;
    display: inline-block;
    .el-date-picker {
      position: relative;
      width: 142px !important;
      height: 30px;
      .el-input__inner {
        padding-left: 15px;
        border: 0;
        font-size: 12px;
        background-color: $color4;
      }
    }
    .icon-riqi {
      position: absolute;
      top: 0;
      right: 10px;
      line-height: 32px;
      font-size: 21px;
      color: $mainColor;
    }
  }

  // 分析页面的表格
  .chart-tab {
    width: 100%;
    overflow-x: auto;
    .chart-tab-ul {
      position: relative;
      // min-width: max-content;
      li {
        position: relative;
        display: flex;
        width: 100%;
        padding: 8px 0;
        border-bottom: 1px solid $color162;
        font-size: 12px;
        color: $color143;
        &.tit {
          background-color: $color154;
          p {
            font-size: 12px;
            font-weight: bold;
            color: $color10;
            .hidden-btn {
              margin-left: 10px;
              font-size: 12px;
              cursor: pointer;
            }
          }
        }
        &.content {
          &:nth-of-type(2n-1) {
            background-color: $color161;
          }
          &:nth-of-type(2n) {
            background-color: #fff;
          }
          &:hover {
            &:before {
              position: absolute;
              top: 0;
              left: 0;
              width: 3px;
              height: 100%;
              background-color: $color164;
              content: "";
            }
            background-color: $color163 !important;
          }
          p {
            &:first-of-type {
              color: $color6;
            }
          }
        }
        p {
          flex: 1;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          min-width: 50px;
          line-height: 23px;
          padding: 0 10px;
          text-align: center;
          .tools-box {
            display: inline-flex;
            align-items: center;
            width: 14px;
            margin-left: 10px;
            .tools-btn {
              margin-right: 10px;
              font-size: 14px;
              cursor: pointer;
            }
          }
        }
        p:nth-child(2) {
          flex: 0;
          width: 50px;
        }
      }
    }
  }
}
.analysis-page {
  position: relative;
  width: 100%;
  // padding-top: 0.3rem;
  // min-height: calc(100vh - 1rem);
  background-color: $color152;
}
.container {
  display: flex;
  flex-wrap: wrap;
  min-width: 1240px;
  .main {
    flex: 1;
    width: 100%;
    min-width: 0; // 重点
    padding: 20px 20px 0;
    height: calc(100vh - 0.7rem);
    overflow-y: auto;
    .search-wrap {
      display: flex;
      align-items: baseline;
      .search-left-box {
        width: 35rem;
      }
      .tools {
        position: relative;
        top: 0px;
        display: inline-flex;
        align-items: center;
        justify-content: flex-end;
        width: 100%;
        margin-top: 10px;
        margin-bottom: -10px;
        button {
          width: 100px;
          height: 30px;
          border-color: $mainColor;
          border-radius: 15px;
          font-size: 12px;
          color: $color51;
          background-color: $mainColor;
          cursor: pointer;
          i {
            margin-right: 2px;
          }
        }
        .download-center-btn {
          font-size: 14px;
          margin-left: 10px;
          text-decoration: underline;
          color: #242424;
          cursor: pointer;
          &:hover {
            color: $mainColor;
          }
        }
      }
    }
  }
}
// animate
.slide-fade-enter-active {
  transition: all 0.2s ease;
}
.slide-fade-enter {
  margin-right: -256px;
  opacity: 0;
}
</style>
